Repository navigation
input() asks in the console (P36) - #46
Merged
Merged
Conversation
While a program waits in input(), the console's >>> line becomes its input line with the prompt in front; prompt and answer stay in the transcript as one line. Stop (or Ctrl+D) ends the wait with EOFError. The dialog stays only for hosts that hide the console. Without cross-origin isolation, input() raises RuntimeError with a hint that points to the IDE. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
input()now asks in the console instead of a dialog (P36), like a terminal or exam.net.Behaviour
While a program (or a REPL input such as
repl()) waits ininput(prompt), the console's>>>line becomes the program's input line: the prompt in front, the cursor in it, accent border.Enter sends the line. The prompt and the answer stay in the transcript as one line (
> 2 * (3 + 4)), and the program's output follows. Afterwards the>>>line comes back.Stop (and Ctrl+D in an empty line) ends the wait with
EOFError: EOF when reading a line, as Python does. The program can catch it. Python is not restarted in that case, so the REPL keeps its namespace. Reset still restarts.A recursive REPL of the learner's own works (checked up to 200 inputs deep).
«Tests» asks like ▶ (option (a)): the file runs first, as with Run.
Visualizer: it asks while it records the run, then shows the steps. The
input(...)call is one step whose value is the typed text.Without cross-origin isolation (the embed in LiaScript),
input()raisesRuntimeError: input() is not available here, with a new hintinput-unavailable:input()funktioniert hier nicht: Diese Seite kann nicht auf eine Eingabe warten. In der IDE fragt die Konsole danach.»input()doesn't work here: this page can't wait for an answer. In the IDE, the console asks for it."Before, Pyodide's raw
JsExceptiontext appeared there. The «In IDE öffnen» button is in the macro: glpython-liascript#29.Decisions
>>>line rather than a separate field inside the transcript:<input>element, so after typingrepl()+ return the focus (and, I expect, the iPad's software keyboard) stays. Moving focus to a new element without a tap usually doesn't bring the keyboard up in Safari; that is still to confirm on the iPad.batched) only passes whole lines on. So the bridge doesn't print the prompt before waiting; it printsprompt + answeras one line after Enter. Until that line arrives through the output stream, the console shows it already («answered lines»), so nothing flickers.input()is visible.emptyOutput, during a visualization without output). That never happens in the IDE, so in the IDE it's always the console._glpython_input(...), the bridge's internal name. That was already so; the function is now calledinput.Checks
check-runtime-input.py(new, intest:runtime; the bridge under CPython, with a stub for Pyodide'sjs):EOFError(in a Run, in the REPL, caught by the program);RuntimeErrorwith the hint;input(...)step;input.check-runtime-hints.py/check-error-hints.mjs: the new hint, de/en.check-console-browser.mjs(test:console, Chrome + Pyodide). In a parent page with COOP/COEP:repl()typed in the REPL: three answers in the input line, prompt shown, focus in the line, no>>>line while waiting;EOFErrorwithout restart, and Ctrl+D the same;Without isolation: the error and the hint, no dialog.
IDE:
check-ide-browser.mjshas two new cases: ▶ withinput("Name: ")and no dialog; a recursive REPL plus Stop →EOFError, after which the session still answers. They pass against this branch (packed and installed in the IDE locally), on IDE branchfeature/console-input-check. Its PR follows with the bump once the tag exists.Locally green: lint (the known warning),
test:protocol,test:runtime,test:hints,build:embed+test:console.How it goes live
maindeploys it to GitHub Pages. In LiaScript,input()then stops with theRuntimeErrorand the new hint (live within ~10 minutes, no course bump). Nothing else changes there.v0.1.22), then the IDE PR (bump + browser check). Only after that PR is merged and deployed does the IDE ask in the console.input(). Merging reaches courses only with a patch version bump of the course; without it they keep the old text («Python-input() ist in dieser LiaScript-Einbettung nicht verfügbar.»).Manual tests
IDE (after the bump and deploy), Chrome on the desktop:
name = input("Name: ")/print("Hallo", name): the console asks withName:in front of the line, cursor in it; Enter →Name: Zoë,Hallo Zoë; then>>>comes back.repl()program: ▶, thenrepl()in the REPL, three expressions,ende. The transcript reads like a shell.repl()again, then Stop while it waits:EOFError: EOF when reading a line, no «Python wurde neu gestartet», andberechnen("2 ** 10")still works.EOFError.input(): the console asks first, then the steps;input(...)is one step with the typed text.input()at the top: asks first, then the report.iPad (Safari, IDE):
8. Test 1 and test 2 with the software keyboard. Check three things:
repl()+ return, whether the keyboard stays and the next line can be typed right away;LiaScript (after the embed deploy): a block with
input()→ ▶:RuntimeError: input() is not available herewith the hint below it.Follow-ups (not done here)
input():print("Zahl", end=": ")followed byinput()only shows «Zahl: » after the answer, because Pyodide holds a line without its newline back.input("Zahl: ")is fine. Fixing it needs our own stdout handling instead ofbatched.input()ask as well, but the doctest'sGotthen contains prompt + answer. CPython's doctest would have only the prompt and would read from stdin. Rare in the course.repl()shows the existing note (the replay can't answerinput()). Replaying with the recorded answers would be possible.>>>line it still recalls earlier inputs.🤖 Generated with Claude Code